package cn.com.jinhao.provider.report.service.impl;


import cn.com.jinhao.provider.report.mapper.StatisticsMapper;
import cn.com.jinhao.provider.report.model.Statistics;
import cn.com.jinhao.provider.report.service.StatisticsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Types;
import java.util.HashMap;

/**
 * HotLine
 * <p>Description: 统计业务实现类</p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2019/10/22
 * @since 2019-10-22
 */

@Service
public class StatisticsServiceImpl implements StatisticsService {
    @Autowired
    StatisticsMapper statisticsMapper;

    HashMap map = new HashMap(10);


    @SuppressWarnings("unchecked")
    private void initMap(Statistics statistics) {
        if (StringUtils.isNotBlank(statistics.getZiduan())) {
            map.put("ziduan", statistics.getZiduan());
        }

        if (StringUtils.isNotBlank(statistics.getBumen())) {
            map.put("bumen", statistics.getBumen());
        }

        if (StringUtils.isNotBlank(statistics.getUnit())) {
            map.put("unit", statistics.getUnit());
        }

        if (statistics.getQuantity() != 0) {
            map.put("quantity", statistics.getQuantity());
        }

        if (StringUtils.isNotBlank(statistics.getLevel())) {
            map.put("level", statistics.getLevel());
        }

        if (StringUtils.isNotBlank(statistics.getType())) {
            map.put("type", statistics.getType());
        }


        map.put("deptCode", statistics.getDeptCode());
        map.put("begin", statistics.getBeginDate());
        map.put("end", statistics.getEndDate());
        map.put("result", Types.REF_CURSOR);
        map.put("code", Types.NUMERIC);
        map.put("info", Types.VARCHAR);
    }

    @Override
    public HashMap boardReport(Statistics statistics) {
        this.initMap(statistics);
        try {
            statisticsMapper.boardReport(map);
        } catch (Exception e) {
            throw new IllegalStateException("委办局统计信息出错", e);
        }
        return map;
    }

    @Override
    public HashMap sourceReport(Statistics statistics) {
        this.initMap(statistics);
        try {
            statisticsMapper.sourceReport(map);
        } catch (Exception e) {
            throw new IllegalStateException("事件来源统计信息出错", e);
        }
        return map;
    }

    @Override
    public HashMap urgeLevelReport(Statistics statistics) {
        this.initMap(statistics);
        try {
            statisticsMapper.urgeLevelReport(map);
        } catch (Exception e) {
            throw new IllegalStateException("事件紧急度统计信息出错", e);
        }
        return map;
    }

    @Override
    public HashMap typeReport(Statistics statistics) {
        this.initMap(statistics);
        try {
            statisticsMapper.typeReport(map);
        } catch (Exception e) {
            throw new IllegalStateException("事件大类统计信息出错", e);
        }
        return map;
    }

    @Override
    public HashMap operReport(Statistics statistics) {
        this.initMap(statistics);
        try {
            statisticsMapper.operReport(map);
        } catch (Exception e) {
            throw new IllegalStateException("接线员统计信息出错", e);
        }
        return map;
    }

    @Override
    public HashMap hotlineReport(Statistics statistics) {
        this.initMap(statistics);
        try {
            statisticsMapper.hotlineReport(map);
        } catch (Exception e) {
            throw new IllegalStateException("热线统计信息出错", e);
        }
        return map;
    }
}
